package cxydmmszl.chapter08.t131;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 子矩阵的最大累加和问题
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li> CD27
 *
 * @author habitplus
 * @since 2021-09-05 15:27
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = bf.readLine().split(" ");
        int n = Integer.parseInt(ss[0]);
        int m = Integer.parseInt(ss[1]);
        int[][] matrix = new int[n][m];


        for (int i = 0; i < n; i++) {
            ss = bf.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                matrix[i][j] = Integer.parseInt(ss[j]);
            }
        }
        bf.close();

        int ans = maxSum(matrix);
        System.out.println(ans);
    }

    public static int maxSum(int[][] matrix) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return 0;
        }

        int n = matrix.length;
        int m = matrix[0].length;
        int max = Integer.MIN_VALUE;
        int cur = 0;
        int[] t;
        for (int i = 0; i < n; i++) {
            t = new int[m];
            for (int j = i; j < n; j++) {
                cur = 0;
                for (int k = 0; k < m; k++) {
                    t[k] += matrix[j][k];
                    cur += t[k];
                    max = Math.max(max, cur);
                    cur = Math.max(cur, 0);
                }
            }
        }

        return max;
    }
}
